import 'package:flutter/material.dart';

class PpListElement extends StatefulWidget {
  // 传入参数
  const PpListElement({
    Key? key,
    required this.id,
    required this.title,
    required this.color,
    required this.titleFontWeight,
    required this.titleSize,
    // required this.desc,
    required this.dcolor,
    required this.imgpath,
    required this.onPressed,
    required this.onTap,
    this.code = '',
    this.tagColor = Colors.orange,
    this.tagtextColor = Colors.white,
    required this.child,
    this.tag = '',
    this.belong = '',
  }) : super(key: key,);
  //  说明参数 使用参数widget.id
  final int id;
  // 标题属性
  final String title;
  final String code;
  final Color color;
  final FontWeight titleFontWeight;
  final double titleSize;
  // 说明文字属性
  // final String desc;
  final String tag;
  final Color dcolor;
  final Color tagColor;
  final Color tagtextColor;
  // 图片
  final String imgpath;
  final VoidCallback onPressed;
  final VoidCallback onTap;
  final Widget child;
  final String belong;
  @override
  State<StatefulWidget> createState() => PpListElementState();
}

class PpListElementState extends State<PpListElement> {
  @override
  Widget build(BuildContext context) {
    return theOneListLine(
        widget.color,
        widget.code,
        widget.title,
        widget.titleFontWeight,// FontWeight.bold,18,
        widget.titleSize,
        // widget.desc,// 'The msg is the Desc !',
        widget.dcolor,// Colors.black38,
        widget.imgpath,
        widget.id,
        widget.onPressed,
        widget.onTap,
        widget.child,
        widget.tag,
        widget.tagColor,
        widget.tagtextColor,
        widget.belong,
    );
  }
}
// 标题
Widget theTitle(Color tColor,String title,FontWeight fontWeight,double size){
  return Container(
    padding: const EdgeInsets.only(bottom: 8.0),
    child: Text(
      title,
      style: TextStyle(
        color:tColor,
        fontSize: size, // 18,
        fontWeight: fontWeight,// FontWeight.bold,
      ),
    ),
  );
}

Widget theCode(Color tColor,String code,FontWeight fontWeight,double size){
  return Container(
    padding: const EdgeInsets.only(bottom: 2.0),
    child: Text(
      code,
      style: TextStyle(
        color:tColor,
        backgroundColor: Colors.black12,
        fontSize: size-4, // 18,
        fontWeight: fontWeight,// FontWeight.bold,
      ),
    ),
  );
}

Widget theBelong(Color tColor,String code,FontWeight fontWeight,double size){
  return Container(
    padding: const EdgeInsets.only(bottom: 2.0),
    child: Text(
      code,
      style: TextStyle(
        color:tColor,
        // backgroundColor: Colors.greenAccent,
        fontSize: size-6, // 18,
        fontWeight: fontWeight,// FontWeight.bold,
      ),
    ),
  );
}

// 说明
Widget theDesc(String desc,Color dcolor){
  return Text(
    desc,// 'The msg is the Desc !',
    style: TextStyle(
        color: dcolor,// Colors.grey[500],
        fontSize: 13
    ),
  );
}
// 组合头部（标题+说明）
Widget theDataHead(Color tcolor,String code,String title,FontWeight titleFontWeight,double titleSize,
    // String desc,
    Color dcolor,Widget child,String belong,){
  return Expanded(
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(height: 5,),
        Row(
          children: [
            theTitle(tcolor,title,titleFontWeight,titleSize),
            Text('  '),
            code == ''?SizedBox(height: 1,):theCode(tcolor,code,titleFontWeight,titleSize),
            Text('  '),
            belong == ''?SizedBox(height: 1,):theBelong(Colors.black45,belong,titleFontWeight,titleSize),//tcolor,belong,titleFontWeight,titleSize),
          ],
        ),
        // theDesc(desc,dcolor),
        child
      ],
    ),
  );
}
// 单行左边图片
Widget theListHeadLeft(String imgpath,String tag,Color tagColor,Color tagtextColor){
  return Stack(
    alignment: AlignmentDirectional.center,//指定未定位或部分定位的子组件的对齐方式
    children: <Widget>[
      Container(
        padding: const EdgeInsets.fromLTRB(5, 5, 15, 5),
        child: imgpath.contains('http') ? Image.network(
          imgpath,
          width: 40.0,
          height: 40.0,
          fit: BoxFit.cover,
        ): Image(
          image:imgpath=='' ? AssetImage('assets/images/report2.png') : AssetImage(imgpath),
          width: 40.0,
          height: 40.0,
          fit: BoxFit.cover,
        ),
      ),
    ],
  );
}
// 单行右侧点击图标
Widget theLineCheck(int id,Function onPressed){
  return Container(
    // alignment: Alignment.center,
    child: theButtonCheck(onPressed), // PopupTap(onPressed: (){onPressed();},id: id,)// ButtonCheck(onPressed)
  );
}
Widget theButtonCheck(Function onPressed){
  return TextButton(
    // onPressed: () {MyToast.success2('$id');} ,
      onPressed: () {onPressed();},
      style: ButtonStyle(
        foregroundColor: MaterialStateProperty.all(Color.fromARGB(255, 53, 53, 53)),
        minimumSize: MaterialStateProperty.all(Size(10, 5)),
        padding: MaterialStateProperty.all(EdgeInsets.zero),
        // backgroundColor: MaterialStateProperty.all(Colors.grey),
      ),
      child: Column(
        children: [
        ],
      )
  );
}
// 组合列表单行（图片+头部+按钮）
Widget theOneListLine(
    Color tColor,
    String code,
    String title,
    FontWeight titleFontWeight,
    double titleSize,
    // String desc,
    Color dColor,
    String imgPath,
    int id,
    Function onPressed,
    Function onTap,
    Widget child,
    String tag,
    Color tagColor,
    Color tagTextColor,
    String belong,
    ){
  return InkWell(
    onTap: () {onTap();},
    //列表的背景颜色
    child:tag =='wait'?Container(
        decoration: BoxDecoration(
          color: Colors.black12,
        ),
        padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
        child: Container(
            padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
            decoration: BoxDecoration(
              border:  Border(bottom:BorderSide(width: 1,color: Color(0xffe5e5e5)) ),
            ),
            child:Row(
              children: [
                theListHeadLeft(imgPath,tag,tagColor,tagTextColor),
                // DataHead('Title',FontWeight.bold,18,'The msg is the Desc !',Colors.black38),
                // theDataHead(tColor,code,title,titleFontWeight,titleSize,desc,dColor,child),
                theDataHead(tColor,code,title,titleFontWeight,titleSize,dColor,child,belong),
                theLineCheck(id,onPressed),
              ],
            )
        )
    ):Container(
        padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
        child: Container(
            padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
            decoration: BoxDecoration(
              border: Border(bottom:BorderSide(width: 1,color: Color(0xffe5e5e5)) ),
            ),
            child:Row(
              children: [
                theListHeadLeft(imgPath,tag,tagColor,tagTextColor),
                // DataHead('Title',FontWeight.bold,18,'The msg is the Desc !',Colors.black38),
                // theDataHead(tColor,code,title,titleFontWeight,titleSize,desc,dColor,child),
                theDataHead(tColor,code,title,titleFontWeight,titleSize,dColor,child,belong),
                theLineCheck(id,onPressed),
              ],
            )
        )
    ),);
}